﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.mvc.core.*;

    public class GroupCopyTeamListRender extends GCellRenderer
    {
        private var _lockIcon:GBitmap;
        private var _avatar:GImageBitmap;
        private var _teamNum:GTextFiled;
        private var _name:GTextFiled;
        private var _comBat:GTextFiled;
        private var _everyCombat:GTextFiled;
        private var _operBtn:GButton;
        private var _sgroup:SCopyWaitingGroup;
        private var _bg:ScaleBitmap;
        private var _tcopy:TCopy;
        private var _avatarBg:GBitmap;

        public function GroupCopyTeamListRender()
        {
            return;
        }// end function

        override protected function initSkin() : void
        {
            var _loc_1:* = GlobalClass.getBitmap(BitmapDataConst.AlphaBMD);
            var _loc_2:* = ResourceConst.getScaleBitmap(ImagesConst.selectedBg);
            this.setStyle("downSkin", _loc_2);
            this.setStyle("overSkin", _loc_2);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_2);
            this.setStyle("selectedOverSkin", _loc_2);
            this.setStyle("selectedUpSkin", _loc_2);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(2, 2, 455, 42, this, ImagesConst.MinigBg);
            this._avatarBg = UIFactory.gBitmap(ImagesConst.FriendHeadBg, 2, 2, this);
            this._avatar = UIFactory.gImageBitmap("", 2, 2, this);
            this._lockIcon = UIFactory.gBitmap(ImagesConst.GroupCopyLock, 130, 16, this);
            this._lockIcon.visible = false;
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._teamNum = UIFactory.gTextField("", 58, 23, 60, 20, this, _loc_1);
            this._name = UIFactory.gTextField("", 35, 3, 100, 20, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatHuang2.center();
            this._comBat = UIFactory.gTextField("4000", 139, 13, 100, 20, this, _loc_1);
            this._everyCombat = UIFactory.gTextField("4000", 262, 13, 100, 20, this, _loc_1);
            this._operBtn = UIFactory.gButton(Language.getString(35244), 396, 7, 50, 30, this);
            this._operBtn.drawNow();
            this._operBtn.configEventListener(MouseEvent.CLICK, this.clickApplyHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._teamNum.dispose(param1);
            this._teamNum = null;
            this._name.dispose(param1);
            this._name = null;
            this._comBat.dispose(param1);
            this._comBat = null;
            this._operBtn.dispose(param1);
            this._operBtn = null;
            this._lockIcon.dispose(param1);
            this._lockIcon = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._avatar.dispose(param1);
            this._avatar = null;
            this._avatarBg.dispose(param1);
            this._avatarBg = null;
            this._everyCombat.dispose(param1);
            this._everyCombat = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function alertHandler(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                this.enterCopyHandler();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCancelSignUp));
            }
            return;
        }// end function

        private function enterCopyHandler() : void
        {
            var _loc_1:* = new SGroupOper();
            _loc_1.fromEntityId = Cache.instance.role.entityInfo.entityId;
            _loc_1.toEntityId = this._sgroup.captainId;
            _loc_1.fromPlayer = new SPublicPlayer();
            _loc_1.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
            _loc_1.type = EGroupOperType._EGroupOperTypeApply;
            _loc_1.copyCode = this._tcopy.code;
            _loc_1.fromPlayer.guildId = new SEntityId();
            _loc_1.fromPlayer.copyId = new SEntityId();
            _loc_1.copyCode = this._tcopy.code;
            var _loc_2:* = new Array();
            _loc_2.push(_loc_1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupApplyOper, _loc_2));
            return;
        }// end function

        private function clickApplyHandler(event:MouseEvent) : void
        {
            var _loc_2:* = Cache.instance.cd.getCDDataByKeyType(CDDataType.publicCD, "GroupCopyApply");
            if (this._sgroup.groupId.id == Cache.instance.group.lastGroupId && _loc_2 && _loc_2.isCoolDown)
            {
                return MsgManager.showRollTipsMsg(Language.getString(35245));
            }
            if (Cache.instance.role.entityInfo.level < this._tcopy.enterMinLevel || Cache.instance.role.entityInfo.level > this._tcopy.enterMaxLevel)
            {
                return MsgManager.showRollTipsMsg(Language.getString(30809));
            }
            if (GameController.arena.isMatching)
            {
                Alert.show(Language.getStringByParam(35246, this._tcopy.name), null, Alert.OK | Alert.CANCEL, null, this.alertHandler);
                return;
            }
            if (GameController.copy.heroArenaCopy.isMatching)
            {
                Alert.show(Language.getStringByParam(35247, this._tcopy.name), null, Alert.OK | Alert.CANCEL, null, this.alertHandler);
                return;
            }
            if (Cache.instance.role.entityInfo.combat < this._sgroup.combatLimit)
            {
                return MsgManager.showRollTipsMsg(Language.getString(30814));
            }
            if (this._sgroup.hasPassword)
            {
                GroupCopyPasswordWin.instance.show();
                GroupCopyPasswordWin.instance.data = {sgroup:this._sgroup, tcopy:this._tcopy};
            }
            else
            {
                this.enterCopyHandler();
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            if (param1.sgroup)
            {
                this._sgroup = param1.sgroup;
                this._tcopy = param1.tcopy;
                this._name.text = this._sgroup.groupName;
                this._comBat.text = this._sgroup.combatLimit.toString();
                this._teamNum.text = Language.getStringByParam(35248, this._sgroup.memberNum);
                this._lockIcon.visible = this._sgroup.hasPassword;
                this._everyCombat.text = this._sgroup.averageCombat.toString();
                this._avatar.imgUrl = AvatarUtil.getPlayerAvatarUrl(this._sgroup.captainPlayer.career, this._sgroup.captainPlayer.sex, AvatarUtil.Small);
                this._operBtn.visible = true;
                this._avatarBg.visible = true;
            }
            else
            {
                this._sgroup = null;
                this._tcopy = null;
                this._avatar.bitmapData = null;
                this._name.text = "";
                this._comBat.text = "";
                this._teamNum.text = "";
                this._everyCombat.text = "";
                this._operBtn.visible = false;
                this._lockIcon.visible = false;
                this._avatarBg.visible = false;
            }
            return;
        }// end function

    }
}
